<template>
  <div o-Container>
    <o-list v-bind:source="list.contract" v-bind="{ exported: output }">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img @click="showLookDiaolog(scope)" src="/static/skin/default/MCS/AIGC/Inventory/images/chakan.png" alt="" />
          <img :style="{ opacity: scope.data.row.StatusID == 3 ? '0.5' : '1' }" @click="showEditDialog(scope)"
            src="/static/skin/default/MCS/AIGC/Inventory/images/bianji.png" />
        </div>
      </template>
    </o-list>
    <InvoiceMsg ref="InvoiceMsg" :messageList="messageList"></InvoiceMsg>
    <EditInvoice ref="EditInvoice" :messageList="messageListAdd" @refresh="refresh"></EditInvoice>
  </div>
</template>

<script>
import InvoiceMsg from "../Components/InvoiceMsg.vue";
import EditInvoice from "../Components/EditInvoice.vue";
export default {
  components: {
    InvoiceMsg,
    EditInvoice
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1300, // 菜单表的八爪鱼ID
            cellData: [
              { name: "PayCode", width: 160 }, // 交易订单号
              { name: "Name", width: 360 }, // 权益名称
              { name: "PurchaserID", show: false  },	// 买家ID
              { name: "PurchaserIDName" },	// 买家
              { name: "Quantity" }, // 核销数量
              { name: "UserPayTotalPrice" }, // 核销总金额
              { name: "Status" }, // Status
              { name: "StatusID", show: false }, // Status
              { name: "RefundAmount" }, // 退款金额
              { name: "RefundQuantity" }, // 退款数量
              { name: "PayTime", width: 160 }, // 支付时间
              { name: "Amount", show: false }, // 开票金额
              { name: "BankAccount", show: false }, // 银行账户
              { name: "BankName", show: false }, // 开户银行
              { name: "CompanyAddress", show: false }, // 公司地址
              { name: "CompanyID", show: false }, // 卖家
              { name: "CompanyIDName", show: false }, // 卖家
              { name: "CompanyName", show: false }, // 公司
              { name: "CreateTime", width: 160 }, // 申请时间
              { name: "FilePath", show: false }, // 文件URL
              { name: "ID", show: false }, // ID
              { name: "IsVat", show: false }, // 是否增值税发票
              { name: "Mail", show: false }, // 开票人 邮箱
              { name: "Phone", show: false }, // 联系电话
              { name: "ReopenTime", show: false }, // 重开时间
              { name: "TaxCode", show: false }, // 发票税号
              { name: "InvoiceID", show: false }, // InvoiceID
              { name: "EquityID", show: false }, // EquityID
              { name: "ServiceCompanyName", show: false }, // ServiceCompanyName
              { name: "PurchaseID", show: false },	// 订单id
              { name: "TypeID", show: false },	// TypeID
              { name: "TradeTypeID", show: false },	// TradeTypeID
            ],
            paramData: {}
          },
          configWidth: 60,
          showNumber: true
        }
      },
      messageList: {},
      messageListAdd: {}
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      // const cellData = this.list.contract.data.cellData;
      // // 遍历 cellData，找到符合条件的元素，并添加键值对
      // cellData.forEach(item => {
      //   if (item.name === "CompanyID") {
      //     // 添加 filterKey 和 filterValue
      //     item.filterKey = '=';
      //     item.filterValue = this.octopus.passport.authorization.company == 1 ? '' : this.octopus.passport.authorization.company;
      //   }
      // })
      const paramData = this.list.contract.data.paramData;
      paramData.CompanyID = this.octopus.passport.authorization.company;
    },
    showLookDiaolog(row) {
      this.messageList = row.data.row;

      this.$nextTick(() => {
        this.$refs.InvoiceMsg.drawerOp();
      })
    },
    showEditDialog(row) {
      if (row.data.row.StatusID == 3) {
        return;
      }
      this.messageListAdd = row.data.row;
      this.$nextTick(() => {
        this.$refs.EditInvoice.drawerOp();
      })

    },
    output: function (data) {
      this.octopus.tips.success("下载完成。");
    },
    search: function (cell) { },
    save: function (data) {
      // 保存
      this.octopus.tips.success(data);
      // 刷新list
      this.list.contract.control.load();
      this.back();
    },
    back: function () {
      this.panel.visible = false;
    },
    del: function (row) {
      let o = this;
      // alert("del key: " + JSON.stringify(row));
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.octopus.request.api.post(
            "/Octopus/Engine/Item",
            {
              id: 1188, // 菜单表的八爪鱼ID
              type: "DELETE",
              value: row.ID,
              cellData: [{ name: "ID", defaultValue: row.ID }]
            },
            // 处理回调事件，通过分析data.status.code的状态来实现。
            function (data) {
              if (data.status.code === 200) {
                o.list.contract.control.load();
              } else {
                o.octopus.tips.error(data);
              }
            }
          );
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    refresh() {
      this.list.contract.control.load();
    }
  },
  props: ["oData"]
};
</script>
<style scoped>
.el-message-box {
  background-color: #fff !important;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}
</style>
